package com.gengzp.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.http.HttpClient;
import java.time.Duration;

/**
 * @ClassName HttpClientConfig
 * @Description http请求客户端配置类
 * @Author gengzp
 * @Date 2025/9/28 15:04
 */
@Configuration
public class HttpClientConfig {

    /**
     * 系统内置 http 请求客户端配置 bean, 使用 jdk 提供的 HttpClient
     */
    @Bean
    public HttpClient httpClient() {
        return HttpClient.newBuilder()
                // 连接超时设置
                .connectTimeout(Duration.ofSeconds(60))
                // 启用HTTP/2支持
                .version(HttpClient.Version.HTTP_2)
                // 跟随重定向
                .followRedirects(HttpClient.Redirect.NORMAL)
                .build();
    }

}
